package position;

import echecs.Echiquier.Case;
import echecs.Pieces.Piece;
import static echecs.Echiquier.Case.*;
import static echecs.Pieces.Piece.*;

public class PositionFabrique {

    private static Piece[] PIECES;

    protected static void placer(Piece pPiece, Case pCase) {
        PIECES[valeur(pCase)] = pPiece;
    }

    public static Piece[] diff(Piece[] pieces1, Piece[] pieces2) {
        Piece[] DIFF = new Piece[64];
        int i = 0;
        for (int c = 0; c < 64; c++) {
            if (!pieces1[c].equals(pieces2[c])) {
                DIFF[i] = PIECES[c];
                i++;
            }
        }
        return DIFF;
    }

    private static class PositionInitiale extends Position {

        @Override
        public void placerPieces() {
            PIECES = new Piece[NB_COLONNES * NB_RANGEES];
            placer(TOUR_BLANCHE, a1);
            placer(CAVALIER_BLANC, b1);
            placer(FOU_BLANC, c1);
            placer(DAME_BLANCHE, d1);
            placer(ROI_BLANC, e1);
            placer(FOU_BLANC, f1);
            placer(CAVALIER_BLANC, g1);
            placer(TOUR_BLANCHE, h1);
//        placer(PION_BLANC, a2);
            placer(PION_BLANC, b2);
            placer(PION_BLANC, c2);
            placer(PION_BLANC, d2);
            placer(PION_BLANC, e2);
            placer(PION_BLANC, f2);
            placer(PION_BLANC, g2);
            placer(PION_BLANC, h2);
            placer(PION_NOIR, a7);
            placer(PION_NOIR, b7);
            placer(PION_NOIR, c7);
            placer(PION_NOIR, d7);
            placer(PION_NOIR, e7);
            placer(PION_NOIR, f7);
            placer(PION_NOIR, g7);
            placer(PION_NOIR, h7);
            placer(TOUR_NOIRE, a8);
            placer(CAVALIER_NOIR, b8);
            placer(FOU_NOIR, c8);
            placer(DAME_NOIRE, d8);
            placer(ROI_NOIR, e8);
            placer(FOU_NOIR, f8);
            placer(CAVALIER_NOIR, g8);
            placer(TOUR_NOIRE, h8);
        }

        @Override
        public Piece[] getPieces() {
            return PIECES;
        }
    }

    public enum PositionType {

        INITIALE
    }

    public static Position creerPosition(PositionType pPositionType) {
        switch (pPositionType) {
            case INITIALE:
                return new PositionInitiale();
        }
        throw new IllegalArgumentException();
    }
}


